


var stop = false;
$("#show").bind("click",function(e){
    console.log("start");
    getSpu();

});
$("#noshow").bind("click",function(e){
    console.log("stop");
    stop = true;

});

function getSpu(){
    if(stop==true){
        return;
    }

        $.ajax({
             url: "https://www.gongrenbao.cn/index.php?c=api/du/goatspu",
             type: "GET",
             dataType: "jsonp", //指定服务器返回的数据类型
             success: function (data) {
                 checkData(data['data']['list']);
                 getSpu();
             }
        });
}

function checkData(ids) {

    for(j = 0; j < ids.length; j++) {
        var url="https://www.goat.com/web-api/v1/product_variants/buy_bar_data?productTemplateId="+ids[j]['spu_id']+"&countryCode=US"
        chrome.tabs.create({ url: url }, function(tab) {
            chrome.tabs.executeScript(tab.id, {
             code: 'console.log(window.name)'
            });
        });
    }

}
